import { observable, computed, autorun, when, reaction, action, runInAction } from 'mobx';


class Store {
    @observable array = [];
    @observable obj = {};
    @observable map = new Map();

    @observable string = 'hello';
    @observable number = 1;
    @observable bool = false;

    @action.bound bar() {
        this.string = "bar";
        this.number = 2222
    }
}

var store = new Store();

// var foo = computed(function () {
//     return store.string + "/" + store.number
// });

// foo.observe(function (change) {
//     console.log(change);
// });

// console.log(foo.get());

// store.string = "wmg"


// autorun(() => {
//     console.log(store.string + "/" + store.number)
// })

// store.string = "test autorun"


// when(() => store.bool, () => {
//     console.log('it`s true');
// })
// store.bool = false;
// store.bool = true;


reaction(() => [store.string, store.number], (arr) => {
    console.log(arr.join('//'));
})
// store.string = "reaction test";
// store.number = 111;


//action只触发一次reaction
// var bar = store.bar();
// bar()

runInAction(() => {
    store.string = "runInAction";
    store.number = 30;
});
